
<%
	//Retrieve session variables.
	String type = (String) session.getAttribute("type");
	String user = (String) session.getAttribute("user");

	// Getting information and updating the database.
	java.sql.Connection conn = null;
	try {
		String myJDBCDriver = (String) session.getAttribute("myJDBCDriver");
		String myURL = (String) session.getAttribute("myURL");
		String myUserID = (String) session.getAttribute("myUserID");
		String myPassword = (String) session.getAttribute("myPassword");

		// Connect to the database.
		Class.forName(myJDBCDriver).newInstance();
		java.util.Properties sysprops = System.getProperties();
		sysprops.put("user", myUserID);
		sysprops.put("password", myPassword);
		conn = java.sql.DriverManager.getConnection(myURL, sysprops);

		// Insert the data into the database.
		java.sql.Statement statement = conn.createStatement();
		java.sql.ResultSet rs = statement.executeQuery("SELECT * FROM users WHERE username = '" + user + "'");
		if (rs.next()) {
			java.sql.ResultSetMetaData columns = rs.getMetaData();
			String query = "UPDATE users SET ";
			String values = "";
			for (int i = 3; i <= columns.getColumnCount(); i++) {
				query += columns.getColumnName(i) + "='" + request.getParameter(columns.getColumnName(i))+"',";
			}
			query = query.substring(0, query.length() - 1) + " WHERE username = '" + user +"'";
			statement.executeUpdate(query);
		}
		session.setAttribute("errors", "Profile Updated!");
		session.setAttribute("file", "edit_profile.jsp");
		response.sendRedirect("dashboard.jsp");
	} catch (Exception e) {
		session.setAttribute("errors", e.toString());
		session.setAttribute("file", "edit_profile.jsp");
		response.sendRedirect("dashboard.jsp");
	} finally {
		try {
			conn.close();
		} catch (Exception ee) {
		}
	}
%>